package com.minelx.sqlstructures.statements.parse.select;

import com.minelx.sequence.core.ReturnMatcher;
import com.minelx.sequence.core.StringScanner;
import com.minelx.sequence.pattern.variable.IVariableManager;
import com.minelx.sequence.pattern.variable.VariableManager;

import java.util.function.Function;

public class VariableMappingMatcher<R> implements ReturnMatcher<R, StringScanner> {
	private final ReturnMatcher<IVariableManager, StringScanner> decorated;

	private final Function<IVariableManager, R> mapper;

	public VariableMappingMatcher(ReturnMatcher<IVariableManager, StringScanner> decorated,
	                              Function<IVariableManager, R> mapper) {
		this.decorated = decorated;
		this.mapper = mapper;
	}

	@Override
	public boolean isMatch(StringScanner stringScanner) {
		return decorated.isMatch(stringScanner);
	}

	@Override
	public R onMatched(StringScanner stringScanner) {
		return mapper.apply(decorated.onMatched(stringScanner));
	}
}
